//
//  ICMCarePackageCell.m
//  ICrEAM
//
//  Created by rainimute on 16/10/27.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMCarePackageCell.h"

@implementation ICMCarePackageCell
#pragma mark    设置界面
- (void)setupCarePackageCellWithSelectedState:(BOOL)isSelected andTitle:(NSString *)title{
    self.contentView.backgroundColor = BackgroundColor_White;
    CGSize titleSize = [title sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]}];
    [self.packageTitleLabel changeWidthToOtherWidth:titleSize.width];
    self.packageTitleLabel.text = title;
    self.selectedStateButton.selected = isSelected;
}

- (UIButton *)selectedStateButton{
    if (!_selectedStateButton) {
        _selectedStateButton = [[UIButton alloc]initWithFrame:CGRectMake(10, 20, 10, 10)];
        BorderWidth(_selectedStateButton, 1);
        _selectedStateButton.layer.borderColor = [UIColor grayColor].CGColor;
        CornerRadius(_selectedStateButton, 5.0f);
        [_selectedStateButton setUpButtonWithNormolTitle:@"" selectedTitle:[NSString changeUinicodeStringToNSString:@"\\U25CF"] normolTitleSize:6 selectedTitleSize:6 normolTitleColor:[UIColor blackColor] selectedTitleColor:[UIColor blackColor] normolBcakImage:nil selectedBackImage:nil actionSEL:nil target:nil];
        [self.contentView addSubview:_selectedStateButton];
    }
    return _selectedStateButton;
}

- (UILabel *)packageTitleLabel{
    if (!_packageTitleLabel) {
        _packageTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.selectedStateButton.frame)+5, 15, 0, 20)];
        [_packageTitleLabel setUpLabelWithText:@"" alignment:NSTextAlignmentLeft textSize:18 textColor:[UIColor blackColor]];
        [self.contentView addSubview:_packageTitleLabel];
    }
    return _packageTitleLabel;
}

@end



@implementation ICMCareItemCell
#pragma mark    设置界面
-  (void)setupCareItemCellWithSelectedState:(BOOL)isSelected andTitle:(NSString*)title isHaveSubTitle:(BOOL)isHaveSubTitle andSubTitle:(NSString*)subTitle isLast:(BOOL)isLast ishideBtn:(BOOL)ishide andValue:(NSString *)value{
    self.contentView.backgroundColor = BackgroundColor_White;
    CGSize titleSize = [title sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]}];
    [self.itemTitleLabel changeWidthToOtherWidth:titleSize.width];
    
    self.itemTitleLabel.text = title;
    self.selectedStateButton.selected = isSelected;
    [self.itemTitleLabel changeYToOtherY:isHaveSubTitle?12:16];
    if (!ishide) {
    
        self.itemButton.enabled=isSelected;
        if (isSelected) {
            self.itemButton.backgroundColor=[UIColor clearColor];
        }else{
            self.itemButton.backgroundColor=[UIColor colorWithRed:238/255. green:238/255. blue:238/255. alpha:0.5];
            
        }
        [self.itemButton setTitle:value forState:UIControlStateNormal];
        
    }
    self.itemSubTitleLabel.hidden = !isHaveSubTitle;
    self.itemSubTitleLabel.text = subTitle;
    self.itemTextField.hidden = !isLast;
    self.itemTitleLabel.hidden = isLast;
    self.isLast = isLast;
}
-(UIButton *)itemButton{
    if (!_itemButton) {
        UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.itemTitleLabel.frame)+15, 17.5,75, 20)];
        lable.textColor=[UIColor blackColor];
        lable.text=@"机油类型";
        _itemButton = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lable.frame), 15, 120, 20)];
        [_itemButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
        _itemButton.titleLabel.font=[UIFont systemFontOfSize:16];
        _itemButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [_itemButton addTarget:self action:@selector(itemButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        UIView *line=[[UIView alloc]initWithFrame:CGRectMake(CGRectGetMinX(_itemButton.frame), _itemButton.bottomEdge, 120, 1)];
        line.backgroundColor=[UIColor blackColor];
        [self.contentView addSubview:lable];
        [self.contentView addSubview:_itemButton];
        [self.contentView addSubview:line];
    }
    return _itemButton;
}
-(void)itemButtonClick:(UIButton*)sender{
    if (self.vehicleBlock) {
        self.vehicleBlock();
    }
}
#pragma mark    输入结束
- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (self.isLast && [self.delegate respondsToSelector:@selector(itemTextFieldHaveChanged:)]) {
        [self.delegate itemTextFieldHaveChanged:textField.text];
    }
}
#pragma mark    状态按钮点击
- (void)selectedStateButtonAction:(UIButton*)sender{
    if ([self.delegate respondsToSelector:@selector(itemCellStateButtonAction:)]) {
        [self.delegate itemCellStateButtonAction:self];
    }
}

- (UIButton *)selectedStateButton{
    if (!_selectedStateButton) {
        _selectedStateButton = [[UIButton alloc]initWithFrame:CGRectMake(10, 17.5, 15, 15)];
        [_selectedStateButton setUpButtonWithNormolTitle:nil selectedTitle:nil normolTitleSize:0 selectedTitleSize:0 normolTitleColor:nil selectedTitleColor:nil normolBcakImage:[UIImage imageNamed:@"btn_activity_notchoose"] selectedBackImage:[UIImage imageNamed:Appointment_ActivityChoose] actionSEL:@selector(selectedStateButtonAction:) target:self];
        [self.contentView addSubview:_selectedStateButton];
    }
    return _selectedStateButton;
}

- (UILabel *)itemTitleLabel{
    if (!_itemTitleLabel) {
        _itemTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.selectedStateButton.frame)+5, 12, 0, 20)];
        [_itemTitleLabel setUpLabelWithText:@"" alignment:NSTextAlignmentLeft textSize:18 textColor:[UIColor blackColor]];
        [self.contentView addSubview:_itemTitleLabel];
    }
    return _itemTitleLabel;
}

- (UILabel *)itemSubTitleLabel{
    if (!_itemSubTitleLabel) {
        _itemSubTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.selectedStateButton.frame)+5, 35, ScreenWidth/2-10, 15)];
        [_itemSubTitleLabel setUpLabelWithText:@"" alignment:NSTextAlignmentLeft textSize:14 textColor:[UIColor grayColor]];
        [self.contentView addSubview:_itemSubTitleLabel];
    }
    return _itemSubTitleLabel;
}

- (UITextField *)itemTextField{
    if (!_itemTextField) {
        _itemTextField = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.selectedStateButton.frame)+5, 12, ScreenWidth/2-CGRectGetMaxX(self.selectedStateButton.frame)-80, 20)];
        _itemTextField.font = [UIFont systemFontOfSize:18];
        _itemTextField.placeholder = @"请输入";
        _itemTextField.delegate = self;
        _itemTextField.borderStyle = UITextBorderStyleNone;
        UILabel *subLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, _itemTextField.bottomEdge-3, ActualWidth(120), 1)];
        subLabel.backgroundColor = [UIColor blackColor];
        [_itemTextField addSubview:subLabel];
        [self.contentView addSubview:_itemTextField];
    }
    return _itemTextField;
}


@end








